console.log('你好');
function printName(obj) {
    var _a;
    if (obj.last !== undefined) {
        console.log(obj.last.toUpperCase());
    }
    //或者
    console.log((_a = obj.last) === null || _a === void 0 ? void 0 : _a.toUpperCase());
    return "".concat(obj.first, "-").concat(obj.last);
}
var username = printName({
    first: 'lai'
});
console.log(username);
var changeingString = 'hello world';
changeingString = 'Olá Mundo';
// changeingString
var constantString = 'hello world';
// const req = {url: 'https://example.com', method: 'GET'}
// handleRequest(req.url, req.method as 'GET')
var req = { url: 'https://example.com', method: 'GET' }; //as const 将整个对象转换为类型字面，不可更改
handleRequest(req.url, req.method);
function doSomething(x) {
    if (x === null) {
        //TODO: do nothing
    }
    else {
        console.log('hello, ' + x.toLowerCase());
    }
}
//非空断言运算符（后缀！）
function liveDangerously(x) {
    console.log(x.toFixed());
}
function printAll(str) {
    if (typeof str === "object" && str) {
        for (var _i = 0, str_1 = str; _i < str_1.length; _i++) {
            var s = str_1[_i];
            console.log(s);
        }
    }
    else if (typeof str === 'string') {
        console.log(str);
    }
    else {
        //TODO: do something
    }
}
function geeter(fn) {
    fn("hello, world");
}
function printToConsole(s) {
    console.log(s);
}
geeter(printToConsole);
function doSomethingFn(fn) {
    console.log(fn.description + ' returned ' + fn(6));
}
function Func(someArg) {
    return someArg > 3;
}
Func.description = 'default description';
console.log(typeof Func); //funtion
doSomethingFn(Func);
function fnConstruct(ctor) {
    return new ctor('thc');
}
function firstElement(arr) {
    return arr[0];
}
function map(arr, func) {
    return arr.map(func);
}
var parsed = map(['1', '2', '3'], function (n) { return parseInt(n); });
//约束条件
function longest(a, b) {
    if (a.length >= b.length) {
        return a;
    }
    return b;
}
// function minimumLength<Type extends {length: number}>(
//     obj:Type,
//     minimum: number
// ):Type{
//     if(obj.length>=minimum){
//         return obj
//     }
//     return {length: minimum}
// }
// 指定类型参数
function combine(arr1, arr2) {
    return arr1.concat(arr2);
}
var arrs = combine([1, 2, 3], ['hello']); //注意<string|number>的写法
function makeDate(mOrTimestamp, d, y) {
    if (d !== undefined && y !== undefined) {
        return new Date(y, mOrTimestamp, d);
    }
    return new Date(mOrTimestamp);
}
var d1 = makeDate(15464);
var d2 = makeDate(2023, 8, 10);
// const d3 = makeDate(1,3)
function fail(msg) {
    throw new Error(msg);
}
var args = [8, 5];
// args.push(2)
// error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter.
// const angle = Math.atan2(...args)  
//可能考虑是args的长度会发生改变，此次atan2()的参数就不止2个了，所以报错，解决方案如下：
var argss = [8, 5]; //as const 相当于只读，不可更改
var angles = Math.atan2.apply(Math, argss);
function sumFn(_a) {
    var a = _a.a, b = _a.b, c = _a.c;
    console.log(a + b + c);
}
function paintShap(opt) {
    console.log('x coordinate at ', opt.xPos);
}
//设置默认值,避免出现opt.xPos = undefined的情况
function paintShaps(_a) {
    var shap = _a.shap, _b = _a.xPos, xPos = _b === void 0 ? 0 : _b, _c = _a.yPos, yPos = _c === void 0 ? 0 : _c;
    console.log('x coordinate at ', xPos);
}
var writablePerson = {
    name: 'Hero thc',
    age: 28
};
var readonlyPerson = writablePerson;
console.log(readonlyPerson.age); // 28
writablePerson.age++;
console.log(readonlyPerson.age); //29
var circleData = {
    color: '#f00',
    radius: 20,
    name: '颜色'
};
function identity(arg) {
    return arg;
}
var myIdentity = identity;
//将泛型类型写为对象字面量类型的调用签名
var myIdentity_ = identity;
//泛型类具有泛型接口相似的形状，泛型类在类名称后面的尖括号（<>）中有一个泛型类型参数列表
var GenericNumber = /** @class */ (function () {
    function GenericNumber() {
    }
    return GenericNumber;
}());
var myGenericNumber = new GenericNumber();
myGenericNumber.zeroValue = 0;
myGenericNumber.add = function (x, y) {
    return x + y;
};
